package com.neolix.watch.view;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neolix.watch.R;

import static com.neolix.watch.NeolixApplication.getInstance;
import static com.neolix.watch.util.StringUtil.isNotBlank;

public class BluetoothDeviceItemView extends LinearLayout {

    private TextView deviceAddressTextView;
    private TextView deviceNameTextView;

    public BluetoothDeviceItemView(Context context) {
        super(context);
        initUi();
    }

    public BluetoothDeviceItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initUi();
    }

    public BluetoothDeviceItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initUi();
    }

    protected void initUi() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View container = inflater.inflate(R.layout.bluetooth_devie_item, this, true);

        deviceNameTextView = (TextView) container.findViewById(R.id.device_name);
        deviceAddressTextView = (TextView) container.findViewById(R.id.device_address);
    }

    public void setModel(BluetoothDevice device) {
        String deviceName = device.getName();
        if (isNotBlank(deviceName))
            deviceNameTextView.setText(deviceName);
        else
            deviceNameTextView.setText(getInstance().getString(R.string.unknow_device));
        deviceAddressTextView.setText(device.getAddress());
    }
}
